package com.example.elderlycare.service.Impl;

import com.example.elderlycare.dao.entity.Roster;
import com.example.elderlycare.dao.mapper.RosterMapper;
import com.example.elderlycare.utils.DateUtil;

import javax.annotation.Resource;
import java.util.*;

public class RosterGenerateByParams implements BaseRoster {
    private static final Random RANDOM = new Random();

    @Resource
    RosterMapper rosterMapper;

    @Override
    public List<Roster> generateRosterRecord(Map<String, Object> params) {
        List<Integer> ids = new ArrayList<>();
        if (params.get("ids") != null) {
            ids = (List<Integer>) params.get("ids");
        }
        int length = ids.size();
        List<Roster> rosterList = new ArrayList<>();
        Date startDate = (Date) params.get("startTime");
        Date endDate = (Date) params.get("endTime");
        Date tmpDate = startDate;
        while (!tmpDate.after(endDate)) {
            for (int i = 1; i < 4; i++) {
                Roster.RosterBuilder rosterBuilder = Roster.builder();
                int tmpIndex = RANDOM.nextInt(length - 1);
                rosterBuilder.employeeId(ids.get(tmpIndex)).dutyAt(tmpDate).type(i);
                rosterList.add(rosterBuilder.build());
            }
            tmpDate = DateUtil.addDate(tmpDate);
        }
        return rosterList;
    }
}
